# basic_preprocessing.py
import numpy as np

def extract_basic_features(sequence):
    """提取基础特征（65维）"""
    if len(sequence) < 2:
        return np.zeros(65)

    start_frame = sequence[0]
    end_frame = sequence[-1]

    # 基础位置变化特征
    position_movement = end_frame - start_frame

    # 运动幅度特征
    movement_magnitude = np.linalg.norm(position_movement)
    max_movement = np.max(np.abs(position_movement))

    # 组合特征（63 + 1 + 1 = 65维）
    features = np.concatenate([
        position_movement,      # 63维：关键点位置变化
        [movement_magnitude],   # 1维：运动幅度
        [max_movement]          # 1维：最大运动
    ])

    return features

def calculate_basic_compactness(frame, point_indices):
    """计算基础紧凑度"""
    points = []
    for idx in point_indices:
        points.append(frame[idx * 3:idx * 3 + 3])

    points = np.array(points)
    center = np.mean(points, axis=0)
    distances = [np.linalg.norm(p - center) for p in points]
    return np.mean(distances)
